package com.example.second_home_work

import android.os.Bundle
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import android.widget.Button
import android.widget.LinearLayout
import android.widget.ScrollView
import android.widget.Spinner
import android.widget.TextView

class MainActivity : AppCompatActivity() {

    private lateinit var linearLayout: LinearLayout
    private lateinit var programAdviser: ProgramAdviser

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)

        linearLayout = findViewById(R.id.linearLayout)
        programAdviser = ProgramAdviser()

        val addTextViewButton: Button = findViewById(R.id.addTextViewButton)
        addTextViewButton.setOnClickListener {
            addTextView()
        }

        val programAdviserButton: Button = findViewById(R.id.programAdviserButton)
        programAdviserButton.setOnClickListener {

            showAdvice()
        }

    }

    var flag = 0
    private fun addTextView() {
        val textView = TextView(this)
        textView.textSize = 20f
        flag++
        textView.text = "New TextView："+flag
        linearLayout.addView(textView)
    }

    private fun showAdvice() {
        val spinner = findViewById<Spinner>(R.id.spinner)
        val advice = spinner.selectedItem.toString()
        val finaladvice = programAdviser.getAdvice(advice)

        val programAdviserResult: TextView = findViewById(R.id.programAdviserResult)
        programAdviserResult.text = getString(R.string.program_adviser_result) + finaladvice
    }

}